/*
 * buffer_replace.hpp
 *
 *  Created on: 2016年4月8日
 *      Author: win7
 */


	replace_return replace(int32_t offset, const char* buf, int32_t length){
		return replace(offset, static_cast<const char*>(buf), length);
	}
	replace_return replace(int32_t offset, const buffer_impl& buffer){
		return replace(offset, buffer.get_read_buffer(), buffer.length());
	}
	replace_return replace(int32_t offset, const buffer_impl& buffer, int32_t length){
		return replace(offset, buffer.get_read_buffer(), length);
	}
	replace_return replace(int32_t offset, unsigned char value){
		return replace(offset, static_cast<unsigned char*>(&value), sizeof(value));
	}
	replace_return replace(int32_t offset, unsigned short value){
		value = ::htons(value);
		return replace(offset, (unsigned char*)(&value), sizeof(value));
	}
	replace_return replace(int32_t offset, unsigned int value){
		switch(sizeof(value)){
		case 2:
			value = ::htons(static_cast<uint16_t>(value));
			return replace(offset, (unsigned char*)(&value), sizeof(value));
		case 4:
			value = ::htonl(static_cast<uint32_t>(value));
			return replace(offset, (unsigned char*)(&value), sizeof(value));
		case 8:
			return replace(offset, static_cast<unsigned long long>(value));
		default:
			return default_replace_reaturn;
		}
	}
	replace_return replace(int32_t offset, unsigned long value){
		switch(sizeof(value)){
		case 4:
			value = ::htonl(static_cast<uint32_t>(value));
			return replace(offset, (unsigned char*)(&value), sizeof(value));
		case 8:
			return replace(offset, static_cast<unsigned long long>(value));
		default:
			return default_replace_reaturn;
		}
	}
	replace_return replace(int32_t offset, unsigned long long value){
//		uint32_t low = ::htonl(static_cast<uint32_t>(value&0xFFFFFFFF));
//		uint32_t high = ::htonl(static_cast<uint32_t>((value >> 32)&0xFFFFFFFF));
//		value = (static_cast<uint64_t>(low) << 32) | high;
		value = (static_cast<uint64_t>(::htonl(static_cast<uint32_t>(value&0xFFFFFFFF))) << 32) | ::htonl(static_cast<uint32_t>((value >> 32)&0xFFFFFFFF));
		return replace(offset, (unsigned char*)(&value), sizeof(value));
	}

	replace_return replace(int32_t offset, signed char value){
		return replace(offset, (unsigned char*)(&value), sizeof(value));
	}
	replace_return replace(int32_t offset, signed short value){
		return replace(offset, static_cast<unsigned short>(value));
	}
	replace_return replace(int32_t offset, signed int value){
		return replace(offset, static_cast<unsigned int>(value));
	}
	replace_return replace(int32_t offset, signed long value){
		return replace(offset, static_cast<unsigned long>(value));
	}
	replace_return replace(int32_t offset, signed long long value){
		return replace(offset, static_cast<unsigned long long>(value));
	}

